package com.googlecode.dgwt.client.dojo.data.listener;

/**
 * Represents a listener that cares about transactions done on a collection.
 * 
 * @see com.googlecode.dgwt.client.dojo.data.base.Store
 * 
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public interface TransactionListener<Parent,Item> extends AttachListener<Parent> {

    /**
     * Event fired when an item has been added to the Parent.
     * 
     * @param index
     *            the Parent list index or -1 if it does not have one
     * @param item
     *            the item that was added
     */
    public void onAdd(int index, Item item);
    
    /**
     * Event fired when an item has been removed from the Parent.
     * 
     * @param index
     *            the Parent list index or -1 if it does not have one
     * @param item
     *            the item that was removed
     */
    public void onRemove(int index, Item item);

    /**
     * Event fired when an item has been replaced by another one.
     * 
     * @param index
     *            the Parent list index or -1 if it does not have one
     * @param oldItem
     *            the item that was removed
     * @param newItem
     *            the item that was added
     */
    public void onReplace(int index, Item oldItem, Item newItem);
    
    /**
     * Event fired when the data on an item has been modified.
     * 
     * @param item the item that was modified
     */
    public void onModified(Item item);

}
